#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 0 
struct
{
	int i;
	float f;
	char ch;

}a = { , , },b = { , , },*p = &a;

#endif

#define NAMESIZE 32

struct student_st
{
	int id;
	char name[NAMESIZE];
	int math;
	int chinese;
};

void stu_set(struct student_st *p,struct student_st *q)
{
/*
	p->id = 10011;
	strncpy(p->name,"Alen",NAMESIZE);
	p->math = 98;
	p->chinese = 90;
*/
	*p =  *q;
}

void stu_show(struct student_st *p)
{

	printf("%d %s %d %d\n",p->id,p->name,p->math,p->chinese);



}


void stu_changname(struct student_st *p,char newname[NAMESIZE])
{
	strncpy(p->name, newname,NAMESIZE);
}

void menu(void)
{
	printf("\n\n1.set\n2.changename\n3.show\n4.out\n\n");
}

int main(void)
{
#if 0
	struct student_st stu,tmp;
	char newname[NAMESIZE];	

	printf("plz enter for the stu[id name math chinese]:\n");
	scanf("%d%s%d%d",&tmp.id,&tmp.name,&tmp.math,&tmp.chinese);
	stu_set(&stu,&tmp);
	stu_show(&stu);

	printf("plz enter the newname:\n");
	scanf("%s",newname);

		
	stu_changname(&stu,newname);

	stu_show(&stu);

#endif
	struct student_st stu,tmp;
	char newname[NAMESIZE];	

	char flag = 1,key = 0;
	int ret = 0;
	while(flag)
	{
		menu();

		printf("plz enter for the key(q or Q for quit)");
		ret = scanf("%d",&key);
		if(ret != 1)
		{
			break;
		}
		if (key == 4)
		{	
			flag = 0;
		}
		else if (key == 1)
		{
			printf("plz enter for the stu[id name math chinese]:\n");
			scanf("%d%s%d%d",&tmp.id,&tmp.name,&tmp.math,&tmp.chinese);
			stu_set(&stu,&tmp);
		}
		else if(key == 2)
		{		
			printf("plz enter the newname:\n");
			scanf("%s",newname);
			stu_changname(&stu,newname);
		}
		else if(key == 3)
		{
			stu_show(&stu);		
		}
		else
		{
			exit(1);
		}
		//为什么:117要等1s才执行
		printf("plz wait 1s!");
		sleep(1);	
	}
	printf("ths for you use this system!\n");
	exit(0);
}
